@extends("admin.base")
@section("contents")
    <div class="row "  style="font-family: 'UKIJ Ekran'">
        <div class="col-lg-4  m-auto">
            <div class="card mb-3" style="border-radius: 10px">
                <div class="card-body w-100  ">
                    <h3 style="text-align: center" class="danger">添加电影信息页面</h3>
                    {{--                    <form id="movieform" method="post" action="insertmovie" enctype="multipart/form-data">--}}
                    <form id="movieform" enctype="multipart/form-data">
                        {{--                        @csrf--}}
                        <div class="m-auto  col-10 ">

                            <div class="row">
                                <div class="col-10 m-auto">
                                    <div class="mb-3">
                                        <label class="form-label" for="default-input">电影名称</label>
                                        <input class="form-control " type="text" name="movie_ch"
                                               value="{{isset($movie)?$movie->movie_ch:''}}">
                                        <input class="form-control " type="hidden" name="id"
                                               value="{{isset($movie)?$movie->id:0}}">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-10 m-auto">
                                    <div class="mb-3">
                                        <label class="form-label" for="default-input">كىنو ئىسمى</label>
                                        <input class="form-control " type="text" name="movie_uy"
                                               value="{{isset($movie)?$movie->movie_uy:''}}">
                                    </div>
                                </div>
                            </div>


                            <div class="row">
                                <div class="col-10 m-auto">
                                    <div class="mb-3">
                                        <label class="form-label" for="default-input">海报</label>
                                        <input class="form-control filestyle " type="file" name="image">
                                        @if(isset($movie))
                                            <img src="{{isset($movie)?$movie->image:''}}" width="50px" height="50px">
                                        @endif
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-10 m-auto">
                                    <div class="mb-3">
                                        <label class="form-label" for="default-input">视频</label>
                                        <input class="form-control filestyle " type="file" name="movie">
                                        @if(isset($movie)?'kurbanjan':'yok')
                                            <video src="{{isset($movie)?$movie->movie:''}}" height="100px" width="100px" controls></video>
                                        @endif
                                    </div>
                                </div>
                            </div>


                            <div class="row">
                                <div class="col-10 m-auto">
                                    <div class="mb-3">
                                        <label class="form-label" for="default-input">电影类型</label><br>
                                        <select class="selectpicker form-control" name="type">
                                            <option selected>请选择电影类型</option>
                                            @foreach($types as $type)
                                                <option {{isset($movie)?($movie->type==$type->id?'selected':''):''}} value="{{$type->id}}">{{$type->type_ch}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-10 m-auto">
                                    <div class="mb-3">
                                        <label class="form-label" for="default-input">电影语言</label><br>
                                        <select class="selectpicker form-control" name="lang">
                                            <option selected>请
                                                选择电影语言</option>
                                            @foreach($languages as $lang)
                                                <option  {{isset($movie)?($movie->lang==$lang->id?'selected':''):''}} value="{{$lang->id}}">{{$lang->language_ch}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-10 m-auto">
                                    <div class="mb-3">
                                        <label class="form-label" for="default-input">电影区分</label><br>
                                        <select class="selectpicker form-control" name="country">
                                            <option selected>请选择电影区分</option>
                                            @foreach($countrys as $country)
                                                <option {{isset($movie)?($movie->lang==$country->id?'selected':''):''}} value="{{$country->id}}">{{$country->country_ch}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-10 m-auto">
                                    <div class="mb-3">
                                        <label class="form-label" for="default-input">电影年份</label><br>
                                        <select class="selectpicker form-control" name="year">
                                            <option selected>--请选择电影的年份--</option>
                                            <option {{isset($movie)?($movie->year==1?'selected':''):''}} value="1">1940年前</option>
                                            <option {{isset($movie)?($movie->year==2?'selected':''):''}} value="2">1940~1950年</option>
                                            <option {{isset($movie)?($movie->year==3?'selected':''):''}} value="3">1950~1960年</option>
                                            <option {{isset($movie)?($movie->year==4?'selected':''):''}} value="4">1960~1970年</option>
                                            <option {{isset($movie)?($movie->year==5?'selected':''):''}} value="5">1970~1980年</option>
                                            <option {{isset($movie)?($movie->year==6?'selected':''):''}} value="6">1980~1990年</option>
                                            <option {{isset($movie)?($movie->year==7?'selected':''):''}} value="7">1990~2000年</option>
                                            <option {{isset($movie)?($movie->year==8?'selected':''):''}} value="8">2000~2010年</option>
                                            <option {{isset($movie)?($movie->year==9?'selected':''):''}} value="9">2010~2020年</option>
                                            <option {{isset($movie)?($movie->year==10?'selected':''):''}} value="10">2020~至今</option>
                                        </select>
                                    </div>
                                </div>
                            </div>


                            <div class="row">
                                <div class="col-10 m-auto">
                                    <div class="mb-3">
                                        <label class="form-label" for="default-input">电影得分</label><br>
                                        <input name="score" type="number" class="form-control"
                                               value="{{isset($movie)?$movie->score:''}}">
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-10 m-auto">
                                    <div class="mb-3">
                                        <label class="form-label" for="default-input">排序</label><br>
                                        <input name="order" type="number" class="form-control"
                                               value="{{isset($movie)?$movie->order:''}}">
                                    </div>
                                </div>
                            </div>


                            <div class="row">
                                <div class="col-10 m-auto">
                                    <div class="mb-3">
                                        <label class="form-label" for="default-input">电影介绍</label><br>
                                        <textarea class="form-control" name="description" style="overflow: scroll"
                                                  placeholder="请简单的介绍电影">{{isset($movie)?$movie->description:''}}</textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                        {{--                        <button type="submit" class="btn btn-outline-info">提交</button>--}}
                    </form>
                    <div class="col-4 m-auto">
                        <button onclick="moviesubmit()" class="btn btn-outline-info">提交</button>
                        &nbsp; &nbsp; &nbsp;
                        <button type="reset" class="btn btn-outline-danger">重置</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection


@section("scripts")
    <script>
        function moviesubmit() {
            let data = new FormData(document.getElementById("movieform"));
            console.log(data);
            $.ajax({
                url: "insertmovie",
                dataType: "json",
                data: data,
                processData: false,
                contentType: false,
                async: true,
                type: "POST",
                headers: {'X-CSRF-TOKEN': '{{csrf_token()}}'},
                success: function (req) {
                    swal({
                        title: "操作成功",
                        text: req.title,
                        icon: "success",
                        button: "知道了",
                    }), setTimeout(function () {
                        location.href="kino";
                    }, 1000)
                }
            })
        }
    </script>
@endsection


